<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>管理系统</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layer/layer.js"></script>
    <script>
        <c:if test="${info != null}">
        layer.ready(function(){
            layer.open({
                type: 1,
                area : ["150px", "75px"],
                closeBtn: 0, //不显示关闭按钮
                title : false,
                anim: 6,
                shadeClose: true, //开启遮罩关闭
                time: 2000,
                content:  '<div style="margin: auto; width: 100%; height: 100%" class="alert alert-info" role="alert"><h3 style="text-align: center">${info}</h3></div>'
            });
        });
        </c:if>
    </script>
</head>

<body>
<!--End 左侧导航-->
<%@ include file="../jsp/left.jsp"%>

<!--头部信息-->
<%@ include file="../jsp/head.jsp"%>

<!--End 头部信息-->

<!--页面主要内容-->
<main class="lyear-layout-content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar clearfix">
                        <form class="form-inline" action="${pageContext.request.contextPath}/stu/getList" method="get" id="headForm">
                            <div class="form-group">
                                <label class="sr-only control-label" for="college">学院:</label>
                                <div class="col-md-4 col-md-offset-7">
                                    <select class="selectpicker form-control" name="college" id="college" data-maxwidth="270px" data-width="270px" title="--- 请选择需要筛选的学院信息 ---" onchange="getProfession()">

                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="sr-only control-label" for="profession">专业:</label>
                                <div class="col-md-4 col-md-offset-11">
                                    <select class="selectpicker form-control" name="profession" id="profession" data-maxwidth="270px" data-width="270px" title="--- 请选择需要筛选的专业信息 ---">

                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-offset-4">
                                <button id="filter" class="btn btn-default" type="submit">查询</button>
                            </div>
                        </form>

                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>
                        <label class="lyear-checkbox checkbox-primary text-center">
                            <input type="checkbox" id="check-all"><span></span>
                        </label>
                    </th>
                    <th class="text-center">姓名</th>
<%--                    <th class="text-center">学号</th>--%>
                    <th class="text-center">性别</th>
<%--                    <th class="text-center">idCard</th>--%>
                    <th class="text-center">学院</th>
                    <th class="text-center">专业</th>
                    <th class="text-center">班级</th>
<%--                    <th class="text-center">email</th>--%>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${studentList}" var="student" varStatus="s">
                <tr>
                    <td>
                        <label class="lyear-checkbox checkbox-primary  text-center col-md-1">
                            <input type="checkbox" name="ids[]" value="1"><span></span>
                        </label>
                    </td>
                    <td class="text-center col-md-2">${student.name}</td>
<%--                    <td class="text-center">${student.sid}</td>--%>
                    <td class="text-center col-md-2">${student.gander}</td>
<%--                    <td class="text-center">${student.idcard}</td>--%>
                    <td class="text-center col-md-2">${student.college}</td>
                    <td class="text-center col-md-2">${student.profession}</td>
                    <td class="text-center col-md-2">${student.clazz}</td>
<%--                    <td class="text-center">${student.email}</td>--%>
                    <td class="text-center col-md-1">
                        <div class="btn-group">
                            <button type="button" onclick="var s = '${student.sid}';view(s);" id="view" class="btn btn-xs btn-default" title="查看" data-toggle="tooltip"><i class="mdi mdi-eye"></i></button>
                            <button type="button" onclick="var s = '${student.sid}';modify(s);" id="modify" class="btn btn-xs btn-default" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></button>
                        </div>
                    </td>
                </tr>
                </c:forEach>
                </tbody>
            </table>
                        </div>
                        <ul class="pagination">
                            <li><a href="${pageContext.request.contextPath}/stu/getList?pg=${currentPage - 1}">«</a></li>
                                <c:forEach varStatus="p" begin="0" end="${pages - 1}">
                            <c:if test="${pages != null}">
                                <li><a href="${pageContext.request.contextPath}/stu/getList?pg=${p.count}">${p.count}</a></li>
                            </c:if>
                            </c:forEach>
                            <li><a href="${pageContext.request.contextPath}/stu/getList?pg=${currentPage + 1}">»</a></li>
                        </ul>

                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layer/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap-select/bootstrap-select.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/main.min.js"></script>
<script>
    function modify(sid) {
        // alert(tid);
        layer.open({
            type: 2,
            title: false,
            closeBtn: 0, //不显示关闭按钮
            shade: [0],
            shadeClose: true,
            area: ['500px', '700px'],
            anim: 2,
            content: ['/stu/toModify?sid=' + sid, 'no'], //iframe的url，no代表不显示滚动条
            end: function () {
                location.reload()
            }
        });
    }
</script>
<script>
    function view(sid) {
        // alert(sid);
        layer.open({
            type: 2,
            title: false,
            closeBtn: 0, //不显示关闭按钮
            shade: [0],
            area: ['500px', '700px'],
            shadeClose: true,
            anim: 2,
            content: ['/stu/view?sid=' + sid, 'no'], //iframe的url，no代表不显示滚动条
        });
    }
</script>

<script>
    $(function ($) {
        $.ajax({
            url: "${pageContext.request.contextPath}/info/getColleges",
            type: "GET",
            data: {},
            dataType: "json",
            success: function (data) {
                console.log(data);
                var target = "";
                for(var col in data) {
                    target += '<option value="'+  data[col]["collegeId"] +'">'+ data[col]["college"] +'</option>';
                }
                var college = $("#college").html(target);
                college.selectpicker('refresh');
                //render方法强制重新渲染引导程序 - 选择ui,如果当您编程时更改任何相关值而影响元素布局，这将非常有用。
                college.selectpicker('render');
            }
        })
    })
    
    function getProfession() {
        var collegeId = $("#college option:selected").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/info/getProfession",
            data: {"collegeId": collegeId},
            dataType: "json",
            type: "GET",
            success: function (data) {
                console.log(data)
                var target = "";
                for(var pro in data) {
                    target += '<option value="'+ data[pro]["professionId"] +'">'+ data[pro]["profession"] +'</option>'
                }
                var profession = $("#profession").html(target);
                profession.selectpicker('refresh');
                //render方法强制重新渲染引导程序 - 选择ui,如果当您编程时更改任何相关值而影响元素布局，这将非常有用。
                profession.selectpicker('render');
            }
        })
    }
</script>



</body>
</html>